import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/18 9:57
 * @description DFS 递归实现
 */
public class Solution2 {
    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        solution2.lexicalOrder(26);
    }
    List<Integer> ans = new ArrayList<>();
    boolean isOver = false;
    public List<Integer> lexicalOrder(int n) {
        for (int i = 1; i <= 9; i++) {
            dfs(i, n);
        }
        return ans;
    }
    public void  dfs(int cur, int n) {
        if (cur > n) {
            isOver = true;
            return;
        }
        ans.add(cur);
        for (int i= 0; i <= 9; i++) {
            dfs(cur * 10 + i, n);
            if (isOver) {
                isOver = false;
                break;
            }
        }
    }
}
